<template>
  <div>
    <el-table-form ref="form" :model="query">
      <el-form-item label="配送计划:">
        <el-select v-model="planCode" filterable clearable @change="modeChange">
          <el-option v-for="l in EnumList" :key="l.planCode" :value="l.planCode" :label="l.planName" />
        </el-select>
      </el-form-item>
      <template v-slot:btns>
        <el-button v-permission="11" type="primary" icon="el-icon-search" @click="search">查询</el-button>
      </template>
    </el-table-form>
    <el-button v-permission="12" style="margin-bottom: 5px;" type="primary" @click="audit">审核</el-button>
    <lb-table
      ref="lbTable"
      v-el-height-adaptive-table="{bottomOffset:10}"
      v-loading="$loadingPlugin.fetchData"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      pagination
      :total="tableData.total"
      custom-column
      @selection-change="handleSelectionChange"
      @fetch="fetchData"
    />
  </div>
</template>

<script>
  // import datajson from './data.json'
  import { orderSendPlanList, orderSendPlan2CustomerList, orderSendPlanAudit } from '@/api'
  export default {
    name: 'audit',
    data() {
      return {
        query: {},
        planCode: null,
        EnumList: [],
        submitAuditList: [],
        tableData: {
          total: 0,
          column: [
            { type: 'selection', align: 'center' },
            { type: 'index', align: 'center' },
            { label: '客户编号', prop: 'csmCode' },
            { label: '客户名称', prop: 'csmName' },
            { label: '客户电话', prop: 'csmPhone' },
            { label: '地址', prop: 'csmAddress', showOverflowTooltip: true },
            { label: '配送机构', prop: 'orgName' },
            { label: '所属配送计划', prop: 'planName', showOverflowTooltip: true }
          ],
          data: []
        }
      }
    },
    created() {
      this.getEnum()
    },
    methods: {
      modeChange() {

      },
      search() {
        this.fetchData({})
      },
      handleSelectionChange(val) {
        console.log(val, 'val')
        this.submitAuditList = [...val]
      },
      async audit(row) {
        if (!this.submitAuditList.length) {
          this.$message.error('请选择要审核的客户')
          return ''
        }
        this.$confirm(`确定审核吗？`, '提示', {
          type: 'warning'
        }).then(async() => {
          var list = this.submitAuditList.map(l => {
            return { 'planCode': l.planCode, 'csmAddressId': l.csmAddressId }
          })
          const params = {
            paramJson: list
          }
          const res = await orderSendPlanAudit(params)
          if (res.success) {
            this.$message.success('审核成功')
            this.fetchData({})
          }
        })
      },
      async fetchData({ currentPage = 1, pageSize = 20 }) {
        const params = {
          status: 1,
          planCode: this.planCode,
          currentPage,
          pageSize
        }
        // params[this.query.type] = this.query.csmText
        const res = await orderSendPlan2CustomerList(params)
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
      },
      async getEnum() {
        const params = {
          currentPage: 1,
          pageSize: 999
        }
        const res = await orderSendPlanList(params)
        this.EnumList = res.data.rows
        this.EnumList = this.EnumList.filter(item => item.planName)
      }
    }
  }
</script>
